﻿@using BBICMS.Infrastructure;
@using PagedList;
@using PagedList.Mvc;
@model BBICMS.Model.ViewModel.Back.WorkListVM

@{
    ViewBag.Title = "经典项目";
    ViewBag.PageTitle = ViewBag.Title + "_内容";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}



    <div class="panel panel-default">
        <header class="panel-heading">
            <span class="glyphicon glyphicon-file"></span> @ViewBag.Title
        </header>



        <section class="panel-body">
            <div class="text-right">
                <a class="btn btn-primary" href="@Url.Action("AddWork")"><i class="glyphicon glyphicon-plus"></i> 添加案例</a>
            </div>
        </section>


            <table class="table table-hover table-vmiddle">
                <thead>
                    <tr>
                        <th></th>
                        <th>
                            主题
                        </th>
                        <th>
                            所属分类
                        </th>
                        <th>
                            客户
                        </th>
                        <th>
                            年份
                        </th>
                     
                        <th>
                            <span class="glyphicon glyphicon-time"></span> 创建日期
                        </th>
                        <th>
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var Work in Model.OnePageOfWorks)
                    {
                        var className = Work.Recommend ? "btn-warning" : "btn-default";
                        var actionName = Work.Recommend ? "撤消" : "推荐";
                        
                        <tr class="first">
                            <td>
                                @if (!string.IsNullOrEmpty(Work.ImageUrl))
                                {
                                    <img src="@string.Format("{0}?w=30&h=30&mode=crop", Work.Thumbnail)" class="img-thumbnail" />
                                }
                            </td>

                            <td>
                                @Work.Title
                            </td>
                            <td>
                                @string.Join("；", Work.WorkTypes.Select(t => t.Title))
                            </td>
                            <td>
                                @Work.ClientName
                            </td>
                            <td>
                                @Work.FinishYear
                            </td>
                         


                            <td>@Work.AddedDate.ToShortDateString()</td>
                            <td>
                                <a href="@Url.Action("RecommendWork", new { Id = Work.Id })" class="btn btn-xs recomment-item @className" title="@actionName"><i class="glyphicon glyphicon-star"></i></a>
                                <a href="@Url.Action("EditWork", new { Id = Work.Id })" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i></a>
                                <a href="@Url.Action("DeleteWork", new { Id = Work.Id })" class="btn btn-xs btn-danger delete-work"><i class="glyphicon glyphicon-trash"></i></a>
                            </td>
                        </tr>
                    }

                </tbody>

            </table>






        <footer class="panel-footer">
            <ul class="pagination">
                @Html.PagedListPager(Model.OnePageOfWorks, page => Url.Action("Index", new { page }))
            </ul>
        </footer>


    </div>

<!-- end main container -->
@section footer {

    <script>

        $(function () {
        


            //推荐数据
            $('.recomment-item').click(function (e) {


                var url = $(this).attr('href');
                var that = $(this);
                // console.log(url);
                /*DELETE*/
                $.ajax({
                    url: url,
                    dataType: "json",
                    type: "POST",
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify({}),
                    async: true,
                    processData: false,
                    cache: false,
                    success: function (data) {
                        if (data) {
                            toastr.success('案例已' + that.attr("title") + '成功！', that.attr("title") + '案例');
                            if (that.hasClass('btn-default')) {
                                that.removeClass("btn-default").addClass("btn-warning");
                            } else {
                                that.removeClass("btn-warning").addClass("btn-default");
                            }

                        } else {
                            toastr.error('案例' + that.attr("title") + '失败！', that.attr("title") + '案例');
                        }
                    },
                    error: function (xhr) {
                        toastr.error('案例' + that.attr("title") + '失败！', that.attr("title") + '案例');
                    }
                });

                e.preventDefault();
            })


            //删除数据
            $('.delete-work').click(function (e) {
                var url = $(this).attr('href');
                var that = $(this);
               // console.log(url);
                /*DELETE*/
                $.ajax({
                    url: url,
                    dataType: "json",
                    type: "POST",
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify({}),
                    async: true,
                    processData: false,
                    cache: false,
                    success: function (data) {
                        if (data) {
                            toastr.success('案例已删除成功！', '删除案例');
                            that.closest('tr').remove();
                        } else {
                            toastr.error('案例删除失败！', '删除案例');
                        }
                    },
                    error: function (xhr) {
                        toastr.error('案例删除失败！', '删除案例');
                    }
                });

                e.preventDefault();
            })

        });
    </script>

}